package com.zhucan.commodity.provider;

import com.zhucan.commodity.application.consumer.converter.CommodityConverter;
import com.zhucan.commodity.infrastructure.db.repository.CommodityRepository;
import com.zhucan.common.commodity.CommodityProvider;
import com.zhucan.common.commodity.dto.CommodityDTO;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

/**
 * @author zhuCan
 * @description
 * @since 2022-07-05 15:23
 **/
@Service
@Component
@RequiredArgsConstructor
public class CommodityProviderImpl implements CommodityProvider {

    private final CommodityRepository commodityRepository;

    private final CommodityConverter commodityConverter;

    @Override
    public CommodityDTO info(Long id) {
        return commodityRepository.findById(id)
                .map(commodityConverter::convertDTO)
                .orElse(new CommodityDTO());
    }

}
